package com.bichengcao.googlecodejam.round1a2008;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

public class MinimumScalarProduct {

	static int N;

	public static void main(String[] args) throws IOException {
		Input[] inputs = parseInput("src/com/bichengcao/googlecodejam/round1a2008/A-large-practice.in");
		Output[] outputs = process(inputs);
		writeOutput("src/com/bichengcao/googlecodejam/round1a2008/MinimumScalarProduct.out", outputs);
	}

	static class Input {

		int n;
		int[] x;
		int[] y;
	}

	static class Output {

		long result;
	}
	
	private static Input[] parseInput(String filename) throws IOException {
		BufferedReader in = new BufferedReader(new FileReader(filename));
		N = Integer.parseInt(in.readLine());
		Input[] array = new Input[N];

		for (int i = 0; i < N; i++) {
			Input input = array[i] = new Input();
			input.n = Integer.parseInt(in.readLine());
			String line = in.readLine();
			String[] splits = line.split(" ");
			input.x = new int[input.n];
			for (int j = 0; j < input.n; j++) {
				input.x[j] = Integer.parseInt(splits[j]);
			}
			line = in.readLine();
			splits = line.split(" ");
			input.y = new int[input.n];
			for (int j = 0; j < input.n; j++) {
				input.y[j] = Integer.parseInt(splits[j]);
			}
		}

		in.close();
		return array;
	}

	private static Output[] process(Input[] inputs) {
		Output[] outputs = new Output[N];
		for (int i = 0; i < N; i++) {
			outputs[i] = process(inputs[i]);
		}
		return outputs;
	}

	private static Output process(Input input) {
		Output output = new Output();

		Arrays.sort(input.x);
		Arrays.sort(input.y);
		for (int i = 0; i < input.n; i++) {
			output.result += ((long)input.x[i]) * input.y[input.n - 1 - i];
		}

		return output;
	}

	private static void writeOutput(String filename, Output[] outputs) throws IOException {
		PrintWriter out = new PrintWriter(new FileWriter(filename));
		for (int i = 0; i < N; i++) {
			out.println("Case #" + (i + 1) + ": " + outputs[i].result);
		}
		out.close();
	}
}
